<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="./lib/vue.js"></script>
    <link rel="stylesheet" href="./lib/bootstrap.css">   
    <title>Document</title>
</head>
<body>
<div id="app">

    <div class="panel panel-primary">
            <div class="panel-heading ">
                商品管理列表
            </div>
            <div class="panel-body form-inline">
             <label>id:</label>
             <input type="text" class="form-control" v-model="zID">
             <label>name:</label>
             <input type="text" class="form-control"  v-model="zName">
             <input class="btn btn-primary" type="button" value="添加" @click="add">
             <input type="text"  class="form-control" placeholder="关键字查询" v-model="keywords">
            </div>
    </div>

    <table class="table  table-bordered table-hover table-striped">
        <thead>
            <tr>
                <th>id</th>
                <th>name</th>
                <th>time</th>
                <th>option</th>
            </tr>
        </thead>
        <tbody>
            <tr v-for="(item, index) in search()" :key="item.id" >
                <td>{{item.id}}</td>
                <td>{{item.name}}</td>
                <td>{{item.ctime}}</td>
                <td>
                      <a href=""@click.prevent="del(item.id)">删除</a>
                </td>
            </tr>
        </tbody>
    </table>
</div>
</body>
<script>
    var vm=new Vue({
        el:"#app",
        data:{
            zID:"",
            zName:"",
            keywords:"",
            productList:[
                {id:1,name:"离离原上草",ctime:new Date()},
                {id:2,name:"一岁一枯荣",ctime:new Date()},
                {id:3,name:"野火烧不尽",ctime:new Date()},
                {id:4,name:"野火烧不尽",ctime:new Date()}
            ]
        },
        //添加
        methods:{
            add(){
                this.productList.push({
                    id:this.zID,
                    name:this.zName,
                    ctime:new Date(),
                })
            },
            //删除
            del(id){
               this.productList.some((item,i)=>{
                   if(item.id == id)
                   this.productList.splice(i,1)
               })
            },
            //筛选
            search(){
                return this.productList.filter((item) => { 
                    if (item.name.includes(this.keywords)) {
                        return item
                    }
                })
            }
        },
    })
</script>

</html>